package com.wms.controller;

import com.wms.dto.TypePageQueryDTO;
import com.wms.entity.WmsStorage;
import com.wms.entity.WmsType;
import com.wms.result.PageResult;
import com.wms.result.Result;
import com.wms.service.TypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/type")
@Slf4j
@Api(tags = "类型管理模块")
public class TypeController {
    @Autowired
    private TypeService typeService;

    /**
     * 仓库分页查询
     * @param typePageQueryDTO
     * @return
     */
    @PostMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> page(@RequestBody TypePageQueryDTO typePageQueryDTO){
        PageResult pageResult = typeService.page(typePageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 新增类型
     * @param wmsType
     * @return
     */
    @PostMapping("/save")
    @ApiOperation("新增类型")
    public Result save(@RequestBody WmsType wmsType){
        typeService.save(wmsType);
        return Result.success();
    }

    /**
     * 修改类型
     * @param wmsType
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改类型")
    public Result update(@RequestBody WmsType wmsType){
        typeService.update(wmsType);
        return Result.success();
    }

    /**
     * 批量删除类型
     * @param ids
     * @return
     */
    @DeleteMapping("/delete")
    @ApiOperation("批量删除类型")
    public Result delete(@RequestParam List<Long> ids){
        typeService.delete(ids);
        return Result.success();
    }

    /**
     * 查询所有类型
     * @return
     */
    @GetMapping("/getAll")
    @ApiOperation("查询所有类型")
    public Result getAll(){
        List<WmsType> wmsTypeList = typeService.getAll();
        return Result.success(wmsTypeList);
    }
}
